package trogiup;


import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.LookAndFeel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import org.pushingpixels.substance.api.SubstanceLookAndFeel;
import org.pushingpixels.substance.api.skin.SubstanceSaharaLookAndFeel;

import dangnhap.FromDangNhap;




public class LienHe extends JDialog implements ActionListener {
		
	private JButton btnupdate,btnexit;
	private JTextField txttencongty,txtdiachi,txtdienthoai,txtfax,
	txtmail,txtweb,txtlinhvuc,txtnganhnghe,txtthue,txtlienhe;
	private JTextArea txtAnoidung;
	
	public static void main(String[] args) {
		javax.swing.SwingUtilities.invokeLater(new Runnable()
        {
            public void run()
            {
                JFrame.setDefaultLookAndFeelDecorated(true);
                LookAndFeel laf = new SubstanceSaharaLookAndFeel();
                SubstanceLookAndFeel.setToUseConstantThemesOnDialogs(true);
                //UIManager.put(SubstanceLookAndFeel.TABBED_PANE_CLOSE_BUTTONS_PROPERTY,Boolean.TRUE);
                UIManager.put(SubstanceLookAndFeel.SHOW_EXTRA_WIDGETS, Boolean.TRUE);
                JFrame.setDefaultLookAndFeelDecorated(false);
                JDialog.setDefaultLookAndFeelDecorated(true);
                try {
                        UIManager.setLookAndFeel(laf);
                        LienHe f = new LienHe(null);
    					//frame.setVisible(true);
    					f.setResizable(false);
                } catch (UnsupportedLookAndFeelException e) {
                        e.printStackTrace();
                }
            }
        });		
	}
		public LienHe(JFrame frame){
		
			super(frame,"Liên Hệ",true);
			Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
		    setBounds((screenSize.width-450)/2, (screenSize.height-550)/2, 450, 550);		    
			setResizable(false);			
			this.setLayout(null);
						
			JLabel lbHead = new JLabel("Thông Tin");
			lbHead.setBounds(10, 2, 400, 30);
			lbHead.setFont(new Font("Tahoma", 2, 14));
			lbHead.setFont(new Font("Tahoma", 3, 20));		
			lbHead.setForeground(Color.blue);
			this.add(lbHead);
			
			JLabel lbtencongty = new JLabel("Tên công ty: ");
			lbtencongty.setFont(new Font("Tahoma", 0, 13));
			lbtencongty.setBounds(10, 35, 200, 30);
			this.add(lbtencongty);
			txttencongty = new JTextField();
			txttencongty.setBounds(100, 40, 320, 23);
			this.add(txttencongty);
			JLabel lbdiachi = new JLabel("Địa chỉ: ");
			lbdiachi.setFont(new Font("Tahoma", 0, 13));
			lbdiachi.setBounds(10, 62, 200, 30);
			this.add(lbdiachi);
			txtdiachi = new JTextField();
			txtdiachi.setBounds(100, 67, 320, 23);
			this.add(txtdiachi);
			JLabel lbdienthoai = new JLabel("Điện thoại: ");
			lbdienthoai.setFont(new Font("Tahoma", 0, 13));
			lbdienthoai.setBounds(10, 89, 200, 30);
			this.add(lbdienthoai);
			txtdienthoai = new JTextField();
			txtdienthoai.setBounds(100, 95, 320, 23);
			this.add(txtdienthoai);
			JLabel lbfax = new JLabel("Fax: ");
			lbfax.setFont(new Font("Tahoma", 0, 13));
			lbfax.setBounds(10, 116, 200, 30);
			this.add(lbfax);
			txtfax = new JTextField();
			txtfax.setBounds(100, 122, 320, 23);
			this.add(txtfax);
			JLabel lbmail = new JLabel("Email: ");
			lbmail.setFont(new Font("Tahoma", 0, 13));
			lbmail.setBounds(10, 143, 200, 30);
			this.add(lbmail);
			txtmail = new JTextField();
			txtmail.setBounds(100, 149, 320, 23);
			this.add(txtmail);
			JLabel lbweb = new JLabel("Website: ");
			lbweb.setFont(new Font("Tahoma", 0, 13));
			lbweb.setBounds(10, 170, 200, 30);
			this.add(lbweb);
			txtweb = new JTextField();
			txtweb.setBounds(100, 176, 320, 23);
			this.add(txtweb);
			JLabel lblinhvuc = new JLabel("Lĩnh vực: ");
			lblinhvuc.setFont(new Font("Tahoma", 0, 13));
			lblinhvuc.setBounds(10, 197, 200, 30);
			this.add(lblinhvuc);
			txtlinhvuc = new JTextField();
			txtlinhvuc.setBounds(100, 203, 320, 23);
			this.add(txtlinhvuc);
			JLabel lbnganhnghe = new JLabel("Ngành nghề: ");
			lbnganhnghe.setFont(new Font("Tahoma", 0, 13));
			lbnganhnghe.setBounds(10, 224, 200, 30);
			this.add(lbnganhnghe);
			txtnganhnghe = new JTextField();
			txtnganhnghe.setBounds(100, 230, 320, 23);
			this.add(txtnganhnghe);
			JLabel lbthue = new JLabel("Mã số thuế: ");
			lbthue.setFont(new Font("Tahoma", 0, 13));
			lbthue.setBounds(10, 251, 200, 30);
			this.add(lbthue);
			txtthue = new JTextField();
			txtthue.setBounds(100, 257, 320, 23);
			this.add(txtthue);
			JLabel lblienhe = new JLabel("Người liên hệ: ");
			lblienhe.setFont(new Font("Tahoma", 0, 13));
			lblienhe.setBounds(10, 278, 200, 30);
			this.add(lblienhe);
			txtlienhe = new JTextField();
			txtlienhe.setBounds(100, 283, 320, 23);
			this.add(txtlienhe);			
			JLabel lbnoidung = new JLabel("Nội dung: ");
			lbnoidung.setFont(new Font("Tahoma", 0, 13));
			lbnoidung.setBounds(10, 370, 200, 30);
			this.add(lbnoidung);
			txtAnoidung = new JTextArea();
			JScrollPane scrollPane = new  JScrollPane(txtAnoidung,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane. HORIZONTAL_SCROLLBAR_AS_NEEDED);
			scrollPane.setBounds(100, 311, 320, 150);
			this.add(scrollPane);
			btnupdate = new JButton("Cập Nhật",new ImageIcon(FromDangNhap.rootPath+"images/capnhat.gif"));
			btnupdate.addActionListener(this);
			btnupdate.setBounds(100, 475,85 , 25);
			this.add(btnupdate);	
			
			
			btnexit = new JButton("Kết Thúc",new ImageIcon(FromDangNhap.rootPath+"images/ketthuc.gif"));
			btnexit.addActionListener(this);
			btnexit.setBounds(190, 475, 85, 25);
			this.add(btnexit);
			Dbselect();
			
			
		}
		public void Dbselect(){
			SelectData data = new SelectData();
			Vector<DSJGetLienHe> getLienHes = data.getList();
	        txttencongty.setText(getLienHes.get(0).getTenCongTy());
	        txtdiachi.setText(getLienHes.get(0).getDiachi());
	        txtdienthoai.setText(getLienHes.get(0).getDienthoai());
	        txtfax.setText(getLienHes.get(0).getFax());
	        txtmail.setText(getLienHes.get(0).getEmail());
	        txtweb.setText(getLienHes.get(0).getWeb());
	        txtlinhvuc.setText(getLienHes.get(0).getLinhvuc());
	        txtnganhnghe.setText(getLienHes.get(0).getNganhnghe());
	        txtthue.setText(getLienHes.get(0).getMasothue());
	        txtlienhe.setText(getLienHes.get(0).getNguoilienhe());
	        txtAnoidung.setText(getLienHes.get(0).getNoidung());
		}

		@Override
		public void actionPerformed(ActionEvent e) {
			if(e.getSource() == this.btnupdate){
				
				int reply = JOptionPane.showConfirmDialog(null,"Bạn có chắc muốn cập nhật lại thông tin không?","Title", JOptionPane.YES_NO_OPTION);
				if(reply == JOptionPane.YES_OPTION){
					DSJGetLienHe b = new DSJGetLienHe();
					b.setTenCongTy(txttencongty.getText());
					b.setDiachi(txtdiachi.getText());
					b.setDienthoai(txtdienthoai.getText());
					b.setFax(txtfax.getText());
					b.setEmail(txtmail.getText());
					b.setWeb(txtweb.getText());
					b.setLinhvuc(txtlinhvuc.getText());
					b.setNganhnghe(txtnganhnghe.getText());
					b.setMasothue(txtthue.getText());
					b.setNguoilienhe(txtlienhe.getText());
					b.setNoidung(txtAnoidung.getText());
					b.edit();
					dispose();
				}else if(reply == JOptionPane.NO_OPTION){
					dispose();
				}
			}
			if(e.getSource() == this.btnexit){				
				dispose();
				Dbselect();
			}
		}
		
}
